function R = klinkageU(datasetLabel,Kfile,Lfile,Tfile)
%
% load kernel matrix K from space delimited file Kfile
% calculate distance matrix (as U-vector. U as in LU factorisation)
% cluster data into C and return structure
% K is almost squareform but includes a possibly non-zero diagonal
%   and so once expanded to a matrix needs the diagonal deleting
%
% R.KernelU	kernel matrix as an almost squareform vector 
% R.Kernel	kernel matrix
% R.Distance	distance matrix
% R.Labels	instance truth labels vector (strings)
% R.Truth	instance truth class id vector (ints 1..|#classes|)
% R.Clusters	linkage (cluster) matrix
%

%path = 'C:\sites\price\phd\mypapers\ijcai05\kernels\';
path = 'Z:\simonp\Documents\svn_kernels\';

R.label   = datasetLabel;
R.KernelU = importdata([path,Kfile]);
R.Labels  = importdata([path,Lfile]);
R.Truth   = importdata([path,Tfile]);

% expand vector to square matrix (but creates an unwanted zero diagonal)
R.Kernel = squareform(R.KernelU, 'tomatrix');
%
% remove the unwanted diagonal (by ugly brute force)
len = size(R.Kernel);
len = len(1) - 1;
% crop off the bottom row and the left column
R.Kernel = R.Kernel(1:len, 2:len+1);
% reflect a copy along diagonal
for i = 1:len
	R.Kernel(i:len, i) = R.Kernel(i, i:len);
end

Du = pdist(R.Kernel);
R.Clusters = linkage(Du);

R.Distance = squareform(Du);
